package com.tycmc.dao;

import com.tycmc.common.dataaccess.DruidUtil;
import com.tycmc.common.util.DateUtil;
import org.apache.commons.collections.MapUtils;

import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class VehicleDao {
    public List<Map<String, Object>> vehicleList(String sql) {
        Connection conn = DruidUtil.getConnection();
        PreparedStatement ps = null;
        ResultSet rs = null;
        List<Map<String, Object>> list = new ArrayList<>();
        try {
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while(rs.next()) {
                Map<String, Object> map = new HashMap<>();
                map.put("", rs.getInt(""));
                map.put("", rs.getInt(""));
                list.add(map);
            }
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        } finally {
            DruidUtil.closeConnection(conn, ps, rs);
        }
        return list;
    }
    //查询设备最新数据生成时间
    public Map<String, Object> getLastMsgTime() {
        //将时间
        String sql="select CKZET_VclId,DATE_FORMAT(CKZET_LastMsgTime,'%Y-%m-%d %H:%i:%S')CKZET_LastMsgTime,CKZET_Type  from CacheKZExecTable";
        Connection conn = DruidUtil.getConnection();
        PreparedStatement ps = null;
        ResultSet rs = null;
        Map<String,Object>map=new ConcurrentHashMap<String,Object>();
        try {
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while(rs.next()) {
                map.put(rs.getString("CKZET_VclId")+"_"+rs.getString("CKZET_Type"),rs.getString("CKZET_LastMsgTime"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }  finally {
            DruidUtil.closeConnection(conn, ps, rs);
        }
        return map;
    }
    //查询设备最新数据生成时间
}
